package test;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

import edzest.utils.OracleJDBC;

public class SearchDAO {
	private final String adoNoSQL = "select * from adopters where adono = ?";
	private final String adoNameSQL = "select * from adopters where adoname = ?";
	private final String telSQL = "select * from adopters where tel = ?";
	private final String repSQL = "select * from adopters where repno = ?";
	
	public ArrayList<AdoptersVO> selectAdono(String adono) {
		ArrayList<AdoptersVO> list = new ArrayList<AdoptersVO>();
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		
		try {
			conn = OracleJDBC.openConn();
			ps = conn.prepareStatement(adoNoSQL);
				ps.setString(1, adono);
			rs = ps.executeQuery();
			while(rs.next()) {
				AdoptersVO avo = new AdoptersVO(rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getString(6), rs.getString(7), rs.getString(8));
				list.add(avo);
			}
		} catch (Exception ex){
			ex.printStackTrace();
		} finally {
			OracleJDBC.closeConn(conn, ps, rs);
		}
		return list;
	}
	
	//
	public ArrayList<AdoptersVO> selectAdoname(String adoname) {
		ArrayList<AdoptersVO> list = new ArrayList<AdoptersVO>();
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		
		try {
			conn = OracleJDBC.openConn();
			ps = conn.prepareStatement(adoNameSQL);
				ps.setString(1, adoname);
			rs = ps.executeQuery();
			while(rs.next()) {
				AdoptersVO avo = new AdoptersVO(rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getString(6), rs.getString(7), rs.getString(8));
				list.add(avo);
			}
		} catch (Exception ex){
			ex.printStackTrace();
		} finally {
			OracleJDBC.closeConn(conn, ps, rs);
		}
		return list;
	}
	
	//
	public ArrayList<AdoptersVO> selectTel(String tel) {
		ArrayList<AdoptersVO> list = new ArrayList<AdoptersVO>();
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		
		try {
			conn = OracleJDBC.openConn();
			ps = conn.prepareStatement(telSQL);
				ps.setString(1, tel);
			rs = ps.executeQuery();
			while(rs.next()) {
				AdoptersVO avo = new AdoptersVO(rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getString(6), rs.getString(7), rs.getString(8));
				list.add(avo);
			}
		} catch (Exception ex){
			ex.printStackTrace();
		} finally {
			OracleJDBC.closeConn(conn, ps, rs);
		}
		return list;
	}
	
	//
	public ArrayList<AdoptersVO> selectRep(String rep) {
		ArrayList<AdoptersVO> list = new ArrayList<AdoptersVO>();
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		
		try {
			conn = OracleJDBC.openConn();
			ps = conn.prepareStatement(repSQL);
				ps.setString(1, rep);
			rs = ps.executeQuery();
			while(rs.next()) {
				AdoptersVO avo = new AdoptersVO(rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getString(6), rs.getString(7), rs.getString(8));
				list.add(avo);
			}
		} catch (Exception ex){
			ex.printStackTrace();
		} finally {
			OracleJDBC.closeConn(conn, ps, rs);
		}
		return list;
	}
}
